import React, {Component} from 'react';
import Dialog from 'material-ui/Dialog';
import FlatButton from 'material-ui/FlatButton';

export default class Delete extends Component {
  constructor(props) {
    super(props);
    this.state = {
      title: '你确定删除？',
      content: '删除后活动的参与者也会丢失此活动'
    }
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.method == 'cancel_join') {
      this.setState({
        title: '取消加入此活动？',
        content: '你就不能获取本活动的动态了'
      });
    }

    if (nextProps.method == 'delete_tweet') {
      this.setState({
        title: '删除这个分享？',
        content: ''
      });
    }
  }

  handleClose = () => {
    this.props.handleClose();
  };

  handleConfirm = () => {
    this.props.deleteConfirm(true);
  };

  render() {
  	const actions = [
      <FlatButton
        label="取消"
        onTouchTap={this.handleClose}
      />,
      <FlatButton
        label="确认"
        primary={true}
        onTouchTap={this.handleConfirm}
      />
    ];
  	return (
  	  <Dialog
        actions={actions}
        modal={false}
        open={this.props.open}
        onRequestClose={this.handleClose}
        overlayStyle={{backgroundColor: 'rgba(0,0,0,0.12)'}}
        contentStyle={{width: '100%', maxWidth: 400}}
      >
        {this.state.title}<br />
        {this.state.content}
      </Dialog>
  	);
  }
};
